*Estimates RSZ mean, median and trimmed mean combination forecasts

set more 1

do prepare

do regstandard

*save rszsimple$h$sep$freq, replace

*Generate mean forecasts
capture drop pred spred
egen pred=rowmean(fxx*)
egen spred=rowmean(sfxx*)

do evaluation

capture drop what
capture gen what="RSZ mean" in 1
local s="ResRSZmean$h$sep$freq"
local ds="DataRSZmean$h$sep$freq"

export excel what oos* cduoptsmodelmean* cduoptbuyhold* using results.xlsx in 1/30, sheetmod sheet("`s'") cell(A1) first(var)
export excel yy* pred lnexret modelmean using results.xlsx if yyy>=$firstpred, sheetmod sheet("`s'") cell(A10) first(var)
if $freq==4 & $h==1{
	export excel fxx* wfxx* using results.xlsx if yyy>=$firstpred, sheetmod sheet("Predictions4") cell(I1) first(var)
}
if $freq==12 & $h==1{
	export excel fxx* wfxx* using results.xlsx if yyy>=$firstpred, sheetmod sheet("Predictions12") cell(I1) first(var)
}


*with weighted LS
capture drop pred spred

egen pred=rowmean(wfxx*)
egen spred=rowmean(wsfxx*)

do evaluation

capture drop what
gen what="wRSZ mean " in 1
local s="wResRSZmean$h$sep$freq"


export excel what oos* cduoptsmodelmean* cduoptbuyhold*  using results.xlsx in 1/30, sheetmod sheet("`s'") cell(A1) first(var)



*Generate median forecasts
capture drop pred spred
egen pred=rowmedian(fxx*)
egen spred=rowmedian(sfxx*)

do evaluation

capture drop what
gen what="RSZ median" in 1
local s="ResRSZmedian$h$sep$freq"
local ds="DataRSZmedian$h$sep$freq"



export excel what oos* cduoptsmodelmean* cduoptbuyhold*  using results.xlsx in 1/30, sheetmod sheet("`s'") cell(A1) first(var)
export excel yy* pred lnexret modelmean using results.xlsx if yyy>=$firstpred, sheetmod sheet("`s'") cell(A10) first(var)



*with weighted LS
capture drop pred spred

egen pred=rowmedian(wfxx*)
egen spred=rowmedian(wsfxx*)

do evaluation


capture drop what
gen what="wRSZmedian " in 1
local s="wResRSZmedian$h$sep$freq"


export excel what oos* cduoptsmodelmean* cduoptbuyhold*  using results.xlsx in 1/30, sheetmod sheet("`s'") cell(A1) first(var)




*Generate trimmed mean forecasts

capture drop pred spred
capture drop xrowmin-xrowmax
egen xrowmin=rowmin(fxx*)
egen xrowmax=rowmax(fxx*)
foreach var of varlist dp-lastpredictor{
	replace fxx`var'=. if fxx`var'==xrowmin | fxx`var'==xrowmax
}
egen pred=rowmean(fxx*)

capture drop xrowmin-xrowmax
egen xrowmin=rowmin(sfxx*)
egen xrowmax=rowmax(sfxx*)
foreach var of varlist dp-lastpredictor{
	replace sfxx`var'=. if sfxx`var'==xrowmin | sfxx`var'==xrowmax
}
egen spred=rowmean(sfxx*)

do evaluation

capture drop what
gen what="RSZ trimmed" in 1
local s="ResRSZtrim$h$sep$freq"
local ds="DataRSZtrim$h$sep$freq"


export excel what oos* cduoptsmodelmean* cduoptbuyhold*  using results.xlsx in 1/30, sheetmod sheet("`s'") cell(A1) first(var)
export excel yy* pred lnexret modelmean using results.xlsx if yyy>=$firstpred, sheetmod sheet("`s'") cell(A10) first(var)



*with weighted LS


capture drop pred spred
capture drop xrowmin-xrowmax
egen xrowmin=rowmin(wfxx*)
egen xrowmax=rowmax(wfxx*)
foreach var of varlist dp-lastpredictor{
	replace wfxx`var'=. if wfxx`var'==xrowmin | wfxx`var'==xrowmax
}
egen pred=rowmean(wfxx*)

capture drop xrowmin-xrowmax
egen xrowmin=rowmin(wsfxx*)
egen xrowmax=rowmax(wsfxx*)
foreach var of varlist dp-lastpredictor{
	replace wsfxx`var'=. if wsfxx`var'==xrowmin | wsfxx`var'==xrowmax
}
egen spred=rowmean(wsfxx*)

do evaluation


capture drop what
gen what="wRSZ trimmed" in 1
local s="wResRSZtrim$h$sep$freq"


export excel what oos* cduoptsmodelmean* cduoptbuyhold*  using results.xlsx in 1/30, sheetmod sheet("`s'") cell(A1) first(var)

